<template>
  <el-form ref="registerForm" :model="registerForm" :rules="registerRules" class="find-password-email-form" label-width="110px" label-position="left">
    <!-- 第一步 -->
    <template v-if="currentStep === 1">
      <el-form-item prop="org" label="组织：">
        <el-input
          v-model="registerForm.org"
          type="text"
          size="small"
          style="width:250px"
          auto-complete="off"
          placeholder="组织名称/组织ID"
        >
        </el-input>
      </el-form-item>
      <el-form-item prop="phonenumber" label="邮箱地址：">
        <el-input size="small" style="width:250px" v-model="registerForm.phonenumber" type="text" auto-complete="new-password" placeholder="邮箱地址">
        </el-input>
      </el-form-item>
    </template>
    <!-- 第二步 -->
    <template v-if="currentStep === 2">
      <div class="text-center mt50">已经向深圳XX物流有限公司（001），邮箱XXWL@163.com发送修改链接。</div>
    </template>
    <div>
      <el-form-item label="" label-width="0">
        <!-- 第一步 -->
        <el-button
          v-if="currentStep === 1"
          :loading="loading"
          size="small"
          type="primary"
          style="width:100%;"
          @click.native.prevent="handleRegister"
        >
          <span>确定</span>
        </el-button>
      </el-form-item>
    </div>
  </el-form>
</template>

<script>
import { getCodeImg, register,regSendSms,checkRegister } from "@/api/login";
import { validEmail } from "@/utils/validate"
export default {
  name: "Email",
  data() {
    return {
      codeUrl: "",
      registerForm: {
        org: '',
        phonenumber: "",
        password: "",
        confirmPassword: "",
        code: "",
        uuid: "",
        isRegistered: undefined,
      },
      registerRules: {
        org: [
          { required: true, trigger: "blur", message: "请输入组织名称/组织ID" }
        ],
        phonenumber: [
          { required: true, trigger: "blur", message: "请输入邮箱地址" },
          {
            validator:  (rule, value, callback) => {
              if (!value) {
                callback(new Error('请输入邮箱'));
              } else if (!validEmail(value)) {
                callback(new Error('邮箱格式错误'));
              } else {
                callback();
              }
            },
            trigger: "change"
          }
        ],
      },
      loading: false,
      captchaEnabled: true,
      canSendSms: false,
      timer: null,
      getSms: '获取',
      count: 60,
      isDisabled: false,
      currentStep: 1
    };
  },
  created() {
  },
  methods: {
    handleRegister() {
      this.$refs.registerForm.validate(valid => {
        if (valid) {
          this.currentStep++
          // this.loading = true;
          // register(this.registerForm).then(res => {
            
          // }).catch(() => {
          //   this.loading = false;
          // })
        }
      });
    },
  }
};
</script>

<style rel="stylesheet/scss" lang="scss">
.find-password-email {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100%;
  .find-password-email-form {
    border-radius: 6px;
    background: #ffffff;
    padding: 25px 25px 5px 25px;
    .el-radio-group {
      width: 100%!important;
    }
    .el-radio-button {
      width: 50%!important;
    }
    .el-radio-button__inner {
      width: 100%!important;
    }
  }
  .find-password-email-tip {
    font-size: 13px;
    text-align: center;
    color: #bfbfbf;
  }
  .find-password-email-success {
    .el-form-item {
      margin-bottom: 0!important;
    }
  }
  .el-find-password-email-footer {
    height: 40px;
    line-height: 40px;
    position: fixed;
    bottom: 40px;
    width: 100%;
    text-align: center;
    color: #fff;
    font-family: Arial;
    font-size: 12px;
    letter-spacing: 1px;
  }
}
</style>
